<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script>
            function calc(flag){

                var first=document.getElementById("first").value*1;
                var second=document.getElementById("second").value*1;
                var result=document.getElementById("result");
                var res;
                if(flag=="+"){
                    res=first+second;
                }else if(flag=="-"){
                    res=first-second;
                }else if(flag=="*"){
                    res=first*second;
                }else{
                    res=first/second;
                }
                result.innerHTML=res;
            }
        </script>
    </head>
    <body>
        第一个数： <input type="text" id="first">
        <br>
        第二个数： <input type="text" id="second">
        <br>
        结果：<span id="result"></span>
        <br>
        <input type="button" value="+" onclick="calc('+')">
        <input type="button" value="-" onclick="calc('-')">
        <input type="button" value="*" onclick="calc('*')">
        <input type="button" value="/" onclick="calc('/')">
    </body>
</html>